package edu.ustc.iproject.action.zhaopin;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import edu.ustc.iproject.bean.Company;
import edu.ustc.iproject.bean.Note;
import edu.ustc.iproject.service.CompanyService;
import edu.ustc.iproject.service.NoteService;
import edu.ustc.iproject.service.impl.CompanyServiceImpl;
import edu.ustc.iproject.service.impl.NoteServiceImpl;

public class NoteAction extends ActionSupport {
	
	private int note_id;
	private String note_title;
	private String note_context;
	private Date note_time;
	
	
	public int getNote_id() {
		return note_id;
	}
	public void setNote_id(int noteId) {
		note_id = noteId;
	}
	public String getNote_title() {
		return note_title;
	}
	public void setNote_title(String noteTitle) {
		note_title = noteTitle;
	}
	public String getNote_context() {
		return note_context;
	}
	public void setNote_context(String noteContext) {
		note_context = noteContext;
	}
	public Date getNote_time() {
		return note_time;
	}
	public void setNote_time(Date noteTime) {
		note_time = noteTime;
	}
	
	
	public String saveNote() throws Exception{
		Note note = new Note();
		note.setNote_title(note_title);
		note.setNote_context(note_context);
		note.setNote_time(new Date());
		
		NoteService noteService = new NoteServiceImpl();
		noteService.saveNote(note);
		return SUCCESS;
	}
	
	public String getSingleNote() throws Exception{
		NoteService notesService = new NoteServiceImpl();
		Note note = notesService.getSingleNoteById(note_id);
		note_title = note.getNote_title();
		note_context = note.getNote_context();
		note_time = note.getNote_time();
		return SUCCESS;
	}
	
	public String deleteNote() throws Exception{
		int note_id = this.note_id;
		NoteService noteService = new NoteServiceImpl();
		noteService.removeNote(note_id);
		List<Note> list_note = noteService.listAllNotes();
		HttpServletRequest request = ServletActionContext.getRequest();
	    request.setAttribute("list_note",list_note);
		return SUCCESS;
	}
	
	public String updateNote() throws Exception{
		Note note = new Note();
		NoteService noteService = new NoteServiceImpl();
		note = noteService.getSingleNoteById(note_id);
		note.setNote_title(note_title);
		note.setNote_context(note_context);
		note.setNote_time(note_time);
		noteService.updateNote(note);

		return SUCCESS;
	}
	
	

}
